package com.me.experiment;

import java.util.ArrayList;
import java.util.List;

import com.badlogic.gdx.Gdx;


public class EventManager {
	Scene s_;
	Object objdragged_;
	ArrayList<Object> objects_;

	public int initx_, inity_, objx_, objy_, dragx_, dragy_;
	float time_; // to calculate event position at previous instants
	
	int bouton_selected = -1;
	
	public EventManager(Scene s) {
		s_ = s;
		objdragged_ = null;
		objects_ = null;
		time_ = 0.0f;
	}
	
	public void sortObjects() {
		objects_ = null;
		objects_ = new ArrayList<Object>(s_.objects_.size());
		for(Object o: s_.objects_) objects_.add(o);
		//scene_.sortObjectPerDepth(objects_, 1);
	}
	

	
	public void processEvents(float deltatime) {

		
		if (Gdx.input.justTouched()){  // Touch down event for the moment.
					
			initx_ = Gdx.input.getX();
			inity_ = s_.H_SCREEN -	Gdx.input.getY();
			
//			s_.touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0);
//            s_.guiCam.unproject(s_.touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
			objdragged_ = s_.getObjectAtPositionForSelection(initx_, inity_);
			
			if (objdragged_ != null) {
				objdragged_.onTouchDown();
			}

		}
			
		/*
		 * 
		 * 
		
		
		
		
		for (TouchEvent e : evts) {
			
			
			
///////////////////////////////////////////////////////////////////////				
			if (e.type == TouchEvent.TOUCH_DOWN) {		
				// just for the cursor

				objdragged_ = scene_.getObjectAtPositionForMove(e.x, e.y);
							
				
				if (objdragged_ != null) {
					
					// store touch_down coordinates
					initx_ = e.x;
					inity_ = e.y;
					// get touch position on object
					objx_ = e.x - (int)objdragged_.getAbsx();
					objy_ = e.y - (int)objdragged_.getAbsy();
							
					// Do whatever you have to do
					objdragged_.onTouchDown();
					
					

				}
				if (time_ > 0.02f) {
					time_ = 0.0f;
					dragx_ = e.x;
					dragy_ = e.y;	
				}
				
			}
///////////////////////////////////////////////////////////////////////				
			else if (e.type == TouchEvent.TOUCH_UP) {
				if (objdragged_ != null) {
				objdragged_.onTouchUp();
				}
			}
///////////////////////////////////////////////////////////////////////				
			else if (e.type == TouchEvent.TOUCH_DRAGGED) {

				

	//
				if (objdragged_ != null) {
					
					if (objdragged_.movable_) {
									objdragged_.onTouchDrag(e.x,e.y);
					}
				}
				if (time_ > 0.02f) {
					time_ = 0.0f;
					dragx_ = e.x;
					dragy_ = e.y;	
				}
				
				
			}
			
		}
		time_ += deltatime;  */
	}
}
